
#ifndef COMMON_CH
#define COMMON_CH






/*
#ifndef WIN32

#include "pthread.h"
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <math.h>
#include <inttypes.h>
#include <errno.h>
#include <unistd.h>
#include <sched.h>

#define MIN(a,b) ((a < b) ? a : b)
#define MAX(a,b) ((a > b) ? a : b)

#endif
*/



#define BLOCK_LEN    5000*PACKET_LEN
#define false        0
#define true         1

#define  MPEG1_VIDEO_STREAM    1
#define  MPEG2_VIDEO_STREAM    2
#define	 MPEG1_AUDIO_STREAM    3/* 0x03	*/
#define	 MPEG2_AUDIO_STREAM    4/* 0x04	*/



#define    CH_AV_STREAM     1
#define    CH_A_STREAM      2
#define    CH_MULTI_STREAM  3
#define    CH_NOT_DEFINE   -1


#define    PACKET_LEN      188

////caimao
#define   MAX_LEN_OF_TK    64*5*1024 /* //bytes*/
#define   MIN_TIME_INTERVAL 20 /*//second */

#define   NULL_TIME 0XFFFFFFFFFFFFFFF 




typedef struct _DirInfo
{
	char     nDirName[64];
	int      nObjKey;
	uint16    nType;
	uint16   nModuleId;
	int      nFilLen;
	int      nIndex;
}DirInfo;

typedef struct _DirStruct
{
	uint16      nObjKey;
	uint16      nModuleId;
	char        nName[256];
	int         nCount;
	int         nIndex;
	DirInfo     nObj[1024];

}DirStruct;










uint32  CRC_MPEG32(uint8 * pBuffer,  int len);

void BuildPAT(uint16 nServiceId,uint16 nTsId,uint16 pmt_pid,uint8 * pReBuf,int  * pReLen);

void BuildSDT(uint16 nServiceId,uint16 nTsId,const uint8 nServiceType,const char *  pSPN,int nSPNLen,const char *  pSN,int nSNLen,uint8 * pReBuf,int * pReLen);

int PrivateDataPacket(uint16 pid,uint8 tableid,uint16 TEId,uint8 version,uint8 *pInBuf,int nInLen,uint8 * pOutBuf,int * nOutLen);



int GetPSI(char * nFielName,uint16 input_pid,uint8 input_tid,uint8 * pReBuf,int * nReLen);



////��С����PCR_Baseֵ
int64  ParsePCR(uint8 * pBuf);

int  PrivateDataPacket_x(uint16  pid,uint8 tableid,uint16 TableExtensionId,uint8 version,
						 uint8 *p_data,int TransDataTotal,uint8 * p_data2,int * nReLen);


//int  BuildBoKongTableFile(const char * pFileName);

//int  ParseBoKongTableFromFile(const char * pFileName);

#endif
